package wonder.com.basketballdemo;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioGroup;


import com.sam.widget.button.StateBitmapImageButton;

import fragment.DiscoveryFragment;
import fragment.MeFragment;
import fragment.MessageFragment;
import fragment.WonderFragment;

public class MainActivity extends AppCompatActivity {
    private RadioGroup navBar;
    private StateBitmapImageButton navBall;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findView();
        initView();
    replaceFragment(WonderFragment.getInstanse());
    }

    private void findView() {
        navBar = (RadioGroup) findViewById(R.id.nav_bar);
      navBall = (StateBitmapImageButton) findViewById(R.id.nav_ball);
    }

    private void initView() {
        navBar.setOnCheckedChangeListener(onCheckedChangeListener);

      navBall.setOnClickListener(onClickListener);
    }

    private void replaceFragment(Fragment fragment) {
        FragmentTransaction a = getSupportFragmentManager().beginTransaction();
        a.replace(R.id.replace, fragment);
        a.commit();
    }

    private RadioGroup.OnCheckedChangeListener onCheckedChangeListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            switch (checkedId) {
                case R.id.wonder_nav_bar:
                    replaceFragment(WonderFragment.getInstanse());
                    break;
                case R.id.discovery_nav_bar:
                    replaceFragment(DiscoveryFragment.getInstanse());
                    break;
                case R.id.message_nan_bar:
                    replaceFragment(MessageFragment.getInstanse());
                    break;
                case R.id.me_nav_bar:
                    replaceFragment(MeFragment.getInstanse());
                    break;
            }
        }
    };


    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
        }
    };

}
